/****************************************************************************
 *
 * Copyright (C) 2003-2008 Los Alamos National Security, LLC
 *                         Packet Analytics Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2 as
 * published by the Free Software Foundation.  You may not use, modify or
 * distribute this program under any other version of the GNU General
 * Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 ****************************************************************************/
package nfse.stats;

import java.sql.Timestamp;

public class StatsEntry {

	public int sensorID = -1;
	public Timestamp startTS = null;
	public Timestamp endTS = null;
	public long dstIP = -1;
	public long srcIP = -1;
	public long dstBytes = -1;
	public long srcBytes = -1;
	public long dstPackets = -1;
	public long srcPackets = -1;
	public int protocol = -1;
	public int dstPort = -1;
	public short direction = -1;

	public static StatsEntry generate(String line) throws Exception {
		StatsEntry stats = new StatsEntry();
		String[] values = line.trim().split(",");
		stats.sensorID = Integer.parseInt(values[0]);
		try {
			stats.startTS = Timestamp.valueOf(values[1]);
		} catch (Exception e) {

		}
		try {
			stats.endTS = Timestamp.valueOf(values[2]);
		} catch (Exception e) {

		}
		stats.dstIP = Long.parseLong(values[3]);
		stats.srcIP = Long.parseLong(values[4]);
		stats.dstPort = Integer.parseInt(values[5]);
		stats.dstBytes = Long.parseLong(values[6]);
		stats.dstPackets = Long.parseLong(values[7]);
		stats.srcBytes = Long.parseLong(values[8]);
		stats.srcPackets = Long.parseLong(values[9]);
		stats.protocol = Short.parseShort(values[10]);
		stats.direction = Short.parseShort(values[11]);
		return stats;
	}
	
	public String toString() {
		String temp = sensorID + "," + startTS + "," + endTS;
		temp += "," + dstIP;
		temp += "," + srcIP;
		temp += "," + dstPort;
		temp += "," + dstBytes;
		temp += "," + dstPackets;
		temp += "," + srcBytes;
		temp += "," + srcPackets;
		temp += "," + protocol;
		temp += "," + direction;
		return temp;
	}
}
